﻿using System.Net.Http;
using System.Web;
using System.Web.Configuration;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Description;
using LunchCommand.Data;
using LunchCommand.Models;
using LunchCommand.Models.Logging;
using LunchCommand.Services;
using LunchCommand.ViewModels;

namespace LunchCommand.Controllers
{
    public class LunchStatusController : ApiController
    {
        private LunchCommandContext databaseContext;

        private WebConfigSettings settings;

        private ILogger logger;

        protected override void Initialize(HttpControllerContext controllerContext)
        {
            base.Initialize(controllerContext);

            this.databaseContext = HttpContext.Current.ApplicationInstance.AsLcAppication().DatabaseContext;
            this.settings = WebConfigSettings.CreateFrom(WebConfigurationManager.AppSettings);
            this.logger = new DatabaseLogger(new LogRepository(this.databaseContext));
        }

        [ResponseType(typeof(LunchStatusViewModel))]
        public HttpResponseMessage Get()
        {
            return this.Request.CreateResponse<LunchStatusViewModel>(
                new LunchService(this.databaseContext, this.settings, this.logger).GetStatus());
        }
    }
}
